package com.hy.servlet;

import com.hy.dao.StudentDAO;
import com.hy.model.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by yoka24443 on 2018-5-16.
 */
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Boolean isSuccess = false;

        StudentDAO dao = new StudentDAO();
        String studentNO = request.getParameter("studentNO");
        Student model = dao.findByStudentNO(studentNO);

        if(model != null) {
            isSuccess = dao.delete(studentNO);
        }

        request.getSession().setAttribute("isSuccess", isSuccess ? 1 : 0);


        request.getRequestDispatcher("delStudentReady.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
